/**
 * Created: 2011-7-19
 * By:		eeorange
 * About:	zju1003 - Crashing Balloon
 * Status:	AC 40ms 180KB
 */
#include <cstdio>
#include <cstring>
#include <cstdlib>

#include <algorithm>
#include <iostream>
#include <string>
using namespace std;

bool deny;
bool nece;

void judge(int x, int y, int p){
//	printf("%d %d %d\n", x, y, p);
	if(x == 1) nece = true;
	if(x == 1 && y == 1) deny = true;
	
	if(p > 1){
		if(x%p == 0) judge(x/p, y, p-1);
		if(y%p == 0) judge(x, y/p, p-1);
		judge(x, y, p-1);
	}
}
	

int main(){
	for(;;){
		int x, y;
		if(scanf("%d%d", &x, &y) != 2) break;
		deny = nece = false;
		if(x > y) swap(x, y);	// if x > y swap
		judge(x, y, 100);
		cout << ((nece && !deny) ? x : y) << endl;
	}
	return 0;
}

